#!/php -q
<?php

// USED FOR TESTING PURPOSES. RUN FROM THE COMMAND LINE BEFORE RUNNING THE SERVER

/* 
	This has been tested and works with Apache 2.2 and PHP5 installed
	on windows XP
 
	Run from command line:
	> php -q run.php

 */

require_once "phpUtilities.inc";
require_once "kushtVars.inc"; // Need this for the constants in the game objects
require_once "Database/dbHandler.class.inc";
require_once "Game/Room.class.inc";
require_once "Game/Exit_.class.inc";
require_once "Game/Item.class.inc";

require_once "Game/BasicStructs.inc";
require_once "Database/defaultStructs.inc";

dbHandler::connect("localhost:3306","kusht","kusht");
dbHandler::delete_db();
dbHandler::install_db();

// FUNDAMENTAL SAVES
// Save all Liquids
foreach($def_liquids as $l) {
	$l->put();
}



$basic_room = new Room();
$basic_room->name = "Outside Esquire's Tavern";
$basic_room->description= "A rather gangly establishment by any measure, Esquire's is one hell of a bar. In any other bar, one's liable to get thrown out for what get's a guy invited in. It's a dive tavern just south of the center city. For residents of the east docks, Esquire's is usually the last stop on the tavern-hopping circuit - the place you go when you're almost too wasted to walk. It's a grimy spot with an L-shaped bar, travelers from all over because the booze are cheap, a few long tables and sawdust on the floor. Everything that hasn't been graffitied has been stolen. Still, Esquire's is a giant of city life, a place for picking up a feisty wench, throwing away your inhibitions and getting way too close to a guy who probably doesn't speak the queen's tongue. Like clockwork a mob of drunken revelers jostle to enter Esquire every Friday. The air inside is thick with the perspiration of way too many people to fit inside. Quite possibly, simply, the best place ever.";
$basic_room->image="tavern1.jpg";

$basic_exit = new Exit_();
$basic_exit->setCommonExit(ENTER,"Esquire's Tavern","inside Esquire's Tavern");
$basic_exit->description="That broken window near the door is STILL broken.";
array_push($basic_room->exits,$basic_exit);

$basic_room2 = new Room();
$basic_room2->name = "Inside Esquire's Tavern";
$basic_room2->description= "Esquire's Tavern, home to some of the worst riff-raff on this side of the seven cities";
$basic_room2->image="innertavern1.jpg";

$basic_exit2 = new Exit_();
$basic_exit2->setCommonExit(LEAVE,"Esquire's Tavern","outside Esquire's Tavern");
$basic_exit2->description="A big oak door to the outside world.";
array_push($basic_room2->exits,$basic_exit2);


$basic_room3 = new Room();
$basic_room3->name = "Entrance to the Slums";
$basic_room3->description= "An alley near the dock's district where one's liable to find all sorts of interesting things. These slums have been part of the city since ancient times, before the modern city was even built up around this area. The slums are thus filled with all sorts of ancient doors and cavities, most of them still unexplored. In the distance, you hear someone yelling about the price of fruit. The smell of tanning leather wafts over from a nearby tanner. A murky canal runs through the district down the docks.";
$basic_room3->image="slum1.jpg";

$basic_exit3 = new Exit_();
$basic_exit3->setCommonExit(WEST);
array_push($basic_room->exits,$basic_exit3);

$basic_exit4 = new Exit_();
$basic_exit4->setCommonExit(EAST);
array_push($basic_room3->exits,$basic_exit4);




// The less direct referencing we have, the easier this will be on the database...
// Just a thought...
// Not True! Actualy, the game does end up saving all the rooms that are connected to a give room
// as a convenience, which also causes it to save all rooms connected to those rooms, etc. (but thankfully only if unsaved)
$basic_exit4->to_room=$basic_room;
$basic_exit3->to_room=$basic_room3;
$basic_exit2->to_room=$basic_room;
$basic_exit->to_room=$basic_room2;

$basic_room3->execute_interval = 1 * MIN; // seconds
$basic_room3->timed_script_code = '
if ($parent->is_empty()) {
foreach(World::$char_list as $person) {
	$person->send(\'The talking room is talking to show how game/zone updates are performed\');
}}'; // Rule of thumb for rooms: Update them when empty if it's not essential


$basic_room->put();

$totem = new Item();
$totem->name = "The Black Obelisk";
$totem->short_descr = "An object of immense size and power radiates before you";
$totem->db_set(NOT_TAKEABLE); // Remember to use db_set when in editing mode!!
$totem->put();

// Test of an Algorithmic Generator
// Still bugged... but almost there
/*$i = 0;
$currentRoom = $basic_room;
while($i < 100) {
	$i++;

	$R = rand(0,3);
	
	$newR = new Room();
	$newR->name = "Algorithmically Generated Title";
	$newR->description= "Algorithmically Generated Description";
	$newR->image="slum1.jpg";
	
	$newE = new Exit_();
	$newA = new Exit_();
	
	if($R == 0) { // North
		if($currentRoom->has_exit("north")) { continue; }
		$newE->setCommonExit(NORTH);
		$newA->setCommonExit(SOUTH);
	} elseif($R == 1) { // SOUTH
		if($currentRoom->has_exit("south")) { continue; }
		$newE->setCommonExit(SOUTH);
		$newA->setCommonExit(NORTH);
	} elseif($R == 2) { // North
		if($currentRoom->has_exit("east")) { continue; }
		$newE->setCommonExit(EAST);
		$newA->setCommonExit(WEST);
	} elseif($R == 3) { // North
		if($currentRoom->has_exit("west")) { continue; }
		$newE->setCommonExit(WEST);
		$newA->setCommonExit(EAST);
	}
	
	$newE->to_room = $newR;
	$newA->to_room = $currentRoom;
	
	array_push($currentRoom->exits,$newE);
	array_push($newR->exits,$newA);
	
	$currentRoom->put();
	
	if(rand(0,1)>0) { $currentRoom = $newR; }
	
	$newR->put();
	
}*/


//$basic_room2->put();
//$basic_room3->put();

/*
$john = new Room();
$john->get(13);
echo $john->name."\n";
echo $john->description."\n";
//array_push(World::$room_list,$room);*/
		
?>